<?php
namespace app\modules\member\models;

use Yii;
use app\models\Basic;

class MemberWechat extends Basic
{
    
    public static function tableName()
    {
        return '{{%member_wechat}}';
    }

    public function rules()
    {
        return [
            ['wechat_openid', 'required', 'message' => 'wechat_openid不能为空', 'on' => 'add'],
            ['wechat_openid', 'unique', 'message' => 'wechat_openid不能重复', 'on' => 'add'],
            ['wechat_openid', 'string', 'message' => 'wechat_openid必须是字符串',
                         // 'min' => 3, 'tooShort' => 'wechat_openid最短3位',
                         'max' => 56, 'tooLong' => 'wechat_openid最长56位'],
            ['wechat_unionid', 'string', 'message' => 'wechat_unionid必须是字符串',
                         // 'min' => 3, 'tooShort' => 'wechat_unionid最短3位',
                         'max' => 56, 'tooLong' => 'wechat_unionid最长56位'],
            ['wechat_nickname', 'string', 'message' => 'wechat_nickname必须是字符串',
                         // 'min' => 3, 'tooShort' => 'wechat_nickname最短3位',
                         'max' => 256, 'tooLong' => 'wechat_nickname最长256位'],
            ['wechat_sex', 'in', 'range' => ['0', '1', '2'],  'message' => '性别格式不正确'],
            ['wechat_headimgurl', 'string', 'message' => 'wechat_headimgurl必须是字符串',
                         // 'min' => 3, 'tooShort' => 'wechat_headimgurl最短3位',
                         'max' => 512, 'tooLong' => 'wechat_headimgurl最长512位'],
            ['wechat_country', 'string', 'message' => 'wechat_country必须是字符串',
                         // 'min' => 3, 'tooShort' => 'wechat_country最短3位',
                         'max' => 16, 'tooLong' => 'wechat_country最长16位'],
            ['wechat_province', 'string', 'message' => 'wechat_province必须是字符串',
                         // 'min' => 3, 'tooShort' => 'wechat_province最短3位',
                         'max' => 16, 'tooLong' => 'wechat_province最长16位'],
            ['wechat_city', 'string', 'message' => 'wechat_city必须是字符串',
                         // 'min' => 3, 'tooShort' => 'wechat_city最短3位',
                         'max' => 16, 'tooLong' => 'wechat_city最长16位'],
        ];
    }


    /*添加会员*/
    public function addWeChat($data)
    {
        $this->scenario = 'add';

        if($this->load($data) and $this->validate()){
            if($this->save(false)){
                $id = $this->getPrimaryKey();
                return $id;
            }
        }
        return false;
    }

    
}